/*
 * @Descripttion:
 * @version: V1.0.0.1
 * @Author: daiyiru
 * @Date: 2023-02-22 22:46:55
 * @LastEditors: daiyiru
 * @LastEditTime: 2023-02-24 15:01:15
 */
const merge = require('webpack-merge');
// const common = require("./webpack.common.js");
const common = require('./webpack.dev.common.js');
// HTML 模板
const HtmlWebpackPlugin = require('html-webpack-plugin');
// 静态资源复制
const CopyWebpackPlugin = require('copy-webpack-plugin');

// 路径获取
const { resolve, getDlls } = require('./utils');

module.exports = merge(common, {
  mode: 'development',
  entry: {
    app: './src/core/',
  },
  output: {
    publicPath: '/',
  },
  // devtool: "inline-source-map",
  devtool: 'source-map',
  devServer: {
    // 热重载
    hot: true,
    // 错误显示在页面中
    overlay: true,
    // 信息打印
    stats: 'errors-only',
    // 自动打开
    open: true,
    host: 'localhost',
    // port:8000,
    host: '0.0.0.0',
    // 代理
    proxy: {
      // "/api": "http://localhost:8888"
      '/api': {
        //target: 'http://192.168.10.104:58081',
        // target: 'http://172.16.7.30:58081',
        // target: 'http://172.16.5.31:58081', // 双喜
        // target: 'http://172.16.9.232:58081', //曹
        // target: 'http://172.16.5.15:58081',
        // target: 'http://10.26.84.106:58081',
        target: 'http://192.168.119.23:58081',
        // target: 'http://172.16.5.21:28081',
        // target: 'http://172.16.5.22:28081',
        // target: 'http://172.16.6.14:28081',
        pathRewrite: {},
        changeOrigin: true,
        secure: false, // 接受 运行在 https 上的服务
      },
      '/init': {
        target: 'http://127.0.0.1:28088',
        pathRewrite: {
          '/init': '',
        },
        changeOrigin: true,
        secure: false, // 接受 运行在 https 上的服务
      },
    },
    // history 模式
    // historyApiFallback: {
    //   index: "src/index.html"
    // }
  },
  plugins: [
    // HTML 模板
    new HtmlWebpackPlugin({
      template: 'public/index.html',
      chunksSortMode: 'none', //解决运行报错问题
      dlls: getDlls(),
    }),
    // 静态资源复制
    new CopyWebpackPlugin([
      {
        from: resolve('static'),
        to: 'static',
        ignore: ['.*'],
      },
      {
        from: resolve('public/config.js'),
        to: 'config.js',
      },
      {
        from: resolve('public/favicon.ico'),
        to: 'favicon.ico',
      },
    ]),
  ],
});
